﻿/*----------------------------------------------------------------
// Copyright (C) ET
// 版权所有。 
//
// 文件名：DBsql

// 文件功能描述：DBHelper操作

// 创建标识：胡进财 20140822
 
// 修改标识：

// 修改描述：

//----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET.Monitor.RealDB
{

    public class DBHelper
    {
        /// <summary>
        /// 数据库操作父类，在此类定义数据库操作要用到的方法
        /// </summary>
        public virtual int RunRowCount(string sqlCmd, out string errMsg)
        {
            errMsg = "";
            return 0;
        }
        public virtual bool RunNonQuery(string sqlCmd, out string errMsg)
        {
            errMsg = "";
            return true;
        }
        public virtual object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, out string errMsg)
        {
            errMsg = "";
            return null;
        }
        public virtual object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, string paras, string value, out string errMsg)
        {
            errMsg = "";
            return null;
        }
        public virtual object RunSingle(string sqlcmd, out string errMsg)
        {
            errMsg = "";
            return null;
        }
        public virtual DataSet RunDataSet(string sqlCmd, out string errMsg)
        {
            errMsg = "";
            return null;
        }
        public virtual DataTable RunDataTable(string sqlCmd, out string errMsg)
        {
            errMsg = "";
            return null;
        }
        public virtual DataRow RunDataRow(string sqlCmd, out string errMsg)
        {
            errMsg = "";
            return null;
        }

        public virtual DataTable GetS2Enotes(string tableName, string[] cName, string orderName, int sCount, int eCount)
        {
            DataTable dt = null;
            return dt;
        }

        public virtual bool RetBoolUpFile(string tableName, string tabCName, string tabName, string fileCName, byte[] fileBytes, out string errMsg)
        {
            errMsg = "";
            bool flag = false;
            return flag;
        }
        public virtual int GetCount(string tableName)
        {
            return 0;
        }

        public virtual bool DownLoadXml(string fileID, string filePath)
        {
            return true;
        }

        public virtual bool RunEditPicture(string sql, byte[] img, int key)
        {
            return true;
        }
        public virtual bool UpDocument(IList<Hashtable> list, string tableName, string documentColumnName, byte[] fileBytes)
        {
            return true;
        }
        public virtual bool UpDocumentEdit(IList<Hashtable> listData, IList<Hashtable> listWhere, string tableName)
        {
            return true;
        }

        public virtual bool AddTable(DataTable dta, string tableName)
        {
            return true;
        }
    }

    public class DB2 : DBHelper
    {
        static string path = "", realtype = "", name = "";
        DBdb2 db = null;
        public DB2(string strIniPath, string strIniRealType, string strIniName)
        {
            path = strIniPath;
            realtype = strIniRealType;
            name = strIniName;
            db = new DBdb2(realtype, path, name);
        }


        public override int RunRowCount(string sqlCmd, out string errMsg)
        {
            return db.RunRowCount(sqlCmd, out errMsg);
        }
        public override bool RunNonQuery(string sqlCmd, out string errMsg)
        {
            return db.RunNonQuery(sqlCmd, out errMsg);
        }
        public override object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, out string errMsg)
        {
            return db.RunSingle_SP(sp_name, ID_KEY, qsrq, jsrq, bz, out errMsg);
        }
        public override object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, string paras, string value, out string errMsg)
        {
            return db.RunSingle_SP(sp_name, ID_KEY, qsrq, jsrq, bz, paras, value, out errMsg);
        }
        public override object RunSingle(string sqlcmd, out string errMsg)
        {
            return db.RunSingle(sqlcmd, out errMsg);
        }
        public override DataSet RunDataSet(string sqlCmd, out string errMsg)
        {
            return db.RunDataSet(sqlCmd, out errMsg);
        }
        public override DataTable RunDataTable(string sqlCmd, out string errMsg)
        {
            return db.RunDataTable(sqlCmd, out errMsg);
        }
        public override DataRow RunDataRow(string sqlCmd, out string errMsg)
        {
            return db.RunDataRow(sqlCmd, out errMsg);
        }
        public override DataTable GetS2Enotes(string tableName, string[] cName, string orderName, int sCount, int eCount)
        {
            return db.GetS2Enotes(tableName, cName, orderName, sCount, eCount);
        }
        public override bool RetBoolUpFile(string tableName, string tabCName, string tabName, string fileCName, byte[] fileBytes, out string errMsg)
        {
            return db.RetBoolUpFile(tableName, tabCName, tabName, fileCName, fileBytes, out errMsg);
        }
        public override int GetCount(string tableName)
        {
            return db.GetCount(tableName);
        }
        public override bool DownLoadXml(string fileID, string filePath)
        {
            return db.DownLoadXml(fileID, filePath);
        }
        public override bool RunEditPicture(string sql, byte[] img, int key)
        {
            return db.RunEditPicture(sql, img, key);
        }
        public override bool UpDocument(IList<Hashtable> list, string tableName, string documentColumnName, byte[] fileBytes)
        {
            return db.UpDocument(list, tableName, documentColumnName, fileBytes);
        }

        public override bool UpDocumentEdit(IList<Hashtable> listData, IList<Hashtable> listWhere, string tableName)
        {
            return db.UpDocumentEdit(listData, listWhere, tableName);
        }

        public override bool AddTable(DataTable dta, string tableName)
        {
            return db.AddTable(dta, tableName);
        }
    }

    public class SQL : DBHelper
    {
        static string path = "", realtype = "", name = "";
        DBsql db = null;
        public SQL(string strIniPath, string strIniRealType, string strIniName)
        {
            path = strIniPath;
            realtype = strIniRealType;
            name = strIniName;
            db = new DBsql(realtype, path, name);
        }


        public override int RunRowCount(string sqlCmd, out string errMsg)
        {
            return db.RunRowCount(sqlCmd, out errMsg);
        }
        public override bool RunNonQuery(string sqlCmd, out string errMsg)
        {
            return db.RunNonQuery(sqlCmd, out errMsg);
        }
        public override object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, out string errMsg)
        {
            return db.RunSingle_SP(sp_name, ID_KEY, qsrq, jsrq, bz, out errMsg);
        }
        public override object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, string paras, string value, out string errMsg)
        {
            return db.RunSingle_SP(sp_name, ID_KEY, qsrq, jsrq, bz, paras, value, out errMsg);
        }
        public override object RunSingle(string sqlcmd, out string errMsg)
        {
            return db.RunSingle(sqlcmd, out errMsg);
        }
        public override DataSet RunDataSet(string sqlCmd, out string errMsg)
        {
            return db.RunDataSet(sqlCmd, out errMsg);
        }
        public override DataTable RunDataTable(string sqlCmd, out string errMsg)
        {
            return db.RunDataTable(sqlCmd, out errMsg);
        }
        public override DataRow RunDataRow(string sqlCmd, out string errMsg)
        {
            return db.RunDataRow(sqlCmd, out errMsg);
        }
        public override DataTable GetS2Enotes(string tableName, string[] cName, string orderName, int sCount, int eCount)
        {
            return db.GetS2Enotes(tableName, cName, orderName, sCount, eCount);
        }
        public override bool RetBoolUpFile(string tableName, string tabCName, string tabName, string fileCName, byte[] fileBytes, out string errMsg)
        {
            return db.RetBoolUpFile(tableName, tabCName, tabName, fileCName, fileBytes, out errMsg);
        }
        public override int GetCount(string tableName)
        {
            return db.GetCount(tableName);
        }
        public override bool DownLoadXml(string fileID, string filePath)
        {
            return db.DownLoadXml(fileID, filePath);
        }

        public override bool RunEditPicture(string sql, byte[] img, int key)
        {
            return db.RunEditPicture(sql, img, key);
        }

        public override bool UpDocument(IList<Hashtable> list, string tableName, string documentColumnName, byte[] fileBytes)
        {
            return db.UpDocument(list, tableName, documentColumnName, fileBytes);
        }

        public override bool UpDocumentEdit(IList<Hashtable> listData, IList<Hashtable> listWhere, string tableName)
        {
            return db.UpDocumentEdit(listData, listWhere, tableName);
        }

        public override bool AddTable(DataTable dta, string tableName)
        {
            return db.AddTable(dta, tableName);
        }
    }

    public class ORACLE : DBHelper
    {
        static string path = "", realtype = "", name = "";
        DBoracle db = null;
        public ORACLE(string strIniPath, string strIniRealType, string strIniName)
        {
            path = strIniPath;
            realtype = strIniRealType;
            name = strIniName;
            db = new DBoracle(realtype, path, name);
        }


        public override int RunRowCount(string sqlCmd, out string errMsg)
        {
            return db.RunRowCount(sqlCmd, out errMsg);
        }
        public override bool RunNonQuery(string sqlCmd, out string errMsg)
        {
            return db.RunNonQuery(sqlCmd, out errMsg);
        }
        public override object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, out string errMsg)
        {
            return db.RunSingle_SP(sp_name, ID_KEY, qsrq, jsrq, bz, out errMsg);
        }
        public override object RunSingle_SP(string sp_name, string ID_KEY, string qsrq, string jsrq, string bz, string paras, string value, out string errMsg)
        {
            return db.RunSingle_SP(sp_name, ID_KEY, qsrq, jsrq, bz, paras, value, out errMsg);
        }
        public override object RunSingle(string sqlcmd, out string errMsg)
        {
            return db.RunSingle(sqlcmd, out errMsg);
        }
        public override DataSet RunDataSet(string sqlCmd, out string errMsg)
        {
            return db.RunDataSet(sqlCmd, out errMsg);
        }
        public override DataTable RunDataTable(string sqlCmd, out string errMsg)
        {
            return db.RunDataTable(sqlCmd, out errMsg);
        }
        public override DataRow RunDataRow(string sqlCmd, out string errMsg)
        {
            return db.RunDataRow(sqlCmd, out errMsg);
        }
        public override DataTable GetS2Enotes(string tableName, string[] cName, string orderName, int sCount, int eCount)
        {
            return db.GetS2Enotes(tableName, cName, orderName, sCount, eCount);
        }
        public override bool RetBoolUpFile(string tableName, string tabCName, string tabName, string fileCName, byte[] fileBytes, out string errMsg)
        {
            return db.RetBoolUpFile(tableName, tabCName, tabName, fileCName, fileBytes, out errMsg);
        }
        public override int GetCount(string tableName)
        {
            return db.GetCount(tableName);
        }
        public override bool DownLoadXml(string fileID, string filePath)
        {
            return db.DownLoadXml(fileID, filePath);
        }

        public override bool RunEditPicture(string sql, byte[] img, int key)
        {
            return db.RunEditPicture(sql, img, key);
        }
        public override bool UpDocument(IList<Hashtable> list, string tableName, string documentColumnName, byte[] fileBytes)
        {
            return db.UpDocument(list, tableName, documentColumnName, fileBytes);
        }

        public override bool UpDocumentEdit(IList<Hashtable> listData, IList<Hashtable> listWhere, string tableName)
        {
            return db.UpDocumentEdit(listData, listWhere, tableName);
        }

        public override bool AddTable(DataTable dta, string tableName)
        {
            return db.AddTable(dta, tableName);
        }
    }
}
